import { Base } from '../../../utils/base.js'
const app = getApp()
class Cart extends Base {
  constructor() {
    super()
  }
  /*向购物车添加项目*/
  addCartData(data, callback) {
    let school_id = wx.getStorageSync('school_id')
    let param = {
      url: app.globalData.api + '/api/v1.0/carts/add/' + school_id,
      data,
      type: 'POST',
      showLoading: true,
      sCallback: (res) => {
        callback && callback(res.data)
      }
    }
    this.request(param)
  }

  /*查询购物车数据*/
  getCartData(data, callback) {
    let param = {
      url: app.globalData.api + '/api/v1.0/carts/list/' + wx.getStorageSync('partner_id'),
      data,
      showLoading: true,
      sCallback: (res) => {
        callback && callback(res.data.data)
      }
    }
    this.request(param)
  }

  /*更新购物车项目*/
  editCartData(data, callback) {
    let param = {
      url: app.globalData.api + '/api/v1.0/carts/edit/' + data['cart_id'],
      data,
      type: 'PUT',
      sCallback: (res) => {
        callback && callback(res.data)
      }
    }
    this.request(param)
  }

  /*删除购物车项目*/
  deleteCartData(data, callback) {
    let param = {
      url: app.globalData.api + '/api/v1.0/carts/edit/' + data['cart_id'],
      data,
      type: 'DELETE',
      sCallback: (res) => {
        callback && callback(res.data)
      }
    }
    this.request(param)
  }
}

export { Cart }
